#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys

import wmi
#pip install wmi  -i https://pypi.tuna.tsinghua.edu.cn/simple
#pip install pypiwin32  -i https://pypi.tuna.tsinghua.edu.cn/simple
c = wmi.WMI()
#处理器
def getCPU(text):
    cpus = []
    cpuinfo = {"CPU信息":"\n"}
    for cpu in c.Win32_Processor():   
        tmpmsg = {}  
        tmpmsg["CPUID"] = cpu.ProcessorId.strip()
        tmpmsg["CPU类型"] = cpu.Name
        tmpmsg['系统名称'] = cpu.SystemName
        try:
            tmpmsg["CPU核数"] = str(cpu.NumberOfCores)
        except:
            tmpmsg["CPU核数"] = '1'
        tmpmsg["CPU主频"] = str(cpu.MaxClockSpeed)
        tmpmsg['CPU位数'] = str(cpu.DataWidth)
        cpus.append(tmpmsg)
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'CPUID:'+tmpmsg['CPUID']+'\n'
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'CPU类型:'+tmpmsg['CPU类型']+'\n'
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'系统名称:'+tmpmsg['系统名称']+'\n'
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'CPU核数:'+tmpmsg['CPU核数']+'\n'
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'CPU主频:'+tmpmsg['CPU主频']+'\n'
        cpuinfo['CPU信息'] = cpuinfo['CPU信息']+'CPU位数:'+tmpmsg['CPU位数']+'\n'
    #print (tmpdict)
    return  cpuinfo

#主板
def getMotherboard(text):
    boards = []
    board = {"主板信息":"\n"}
    for board_id in c.Win32_BaseBoard():
        tmpmsg = {}
        tmpmsg['主板UUID'] = board_id.qualifiers['UUID'][1:-1]   #主板UUID,有的主板这部分信息取到为空值，ffffff-ffffff这样的
        tmpmsg['主板序列号'] = board_id.SerialNumber                #主板序列号
        tmpmsg['主板品牌'] = board_id.Manufacturer       #主板生产品牌厂家
        tmpmsg['主板型号'] = board_id.Product                 #主板型号
        boards.append(tmpmsg)
        board['主板信息'] = board['主板信息']+'主板UUID:'+tmpmsg['主板UUID']+'\n'
        board['主板信息'] = board['主板信息']+'主板序列号:'+tmpmsg['主板序列号']+'\n'
        board['主板信息'] = board['主板信息']+'主板品牌:'+tmpmsg['主板品牌']+'\n'
        board['主板信息'] = board['主板信息']+'主板型号:'+tmpmsg['主板型号']+'\n'
    #print (boards)
    return board

#BIOS
def getBIOS(text):
    bioss = []
    bios = {"BIOS信息":"\n"}
    for bios_id in c.Win32_BIOS():
        tmpmsg = {}
        tmpmsg['BIOS特征码'] = str(bios_id.BiosCharacteristics)   #BIOS特征码
        tmpmsg['BIOS版本'] = bios_id.Version                           #BIOS版本
        tmpmsg['BIOS品牌'] = bios_id.Manufacturer.strip()                 #BIOS固件生产厂家
        tmpmsg['BIOS版本发布日期'] = bios_id.ReleaseDate                   #BIOS释放日期
        tmpmsg['BIOS系统管理版本'] = bios_id.SMBIOSBIOSVersion       #系统管理规范版本
        bioss.append(tmpmsg)
        bios['BIOS信息'] = bios['BIOS信息']+'BIOS特征码:'+tmpmsg['BIOS特征码']+'\n'
        bios['BIOS信息'] = bios['BIOS信息']+'BIOS版本:'+tmpmsg['BIOS版本']+'\n'
        bios['BIOS信息'] = bios['BIOS信息']+'BIOS品牌:'+tmpmsg['BIOS品牌']+'\n'
        bios['BIOS信息'] = bios['BIOS信息']+'BIOS版本发布日期:'+tmpmsg['BIOS版本发布日期']+'\n'
        bios['BIOS信息'] = bios['BIOS信息']+'BIOS系统管理版本:'+tmpmsg['BIOS系统管理版本']+'\n'
    #print (bioss)
    return bios

#硬盘
def getDisk(text):
    disks = []
    diskinfo = {"硬盘信息":"\n"}
    for disk in c.Win32_DiskDrive():
        # print disk.__dict__
        tmpmsg = {}
        tmpmsg['硬盘序列号'] = disk.SerialNumber.strip()
        tmpmsg['硬盘设备ID'] = str(disk.DeviceID)
        tmpmsg['硬盘标签'] = disk.Caption
        tmpmsg['硬盘大小'] = str(disk.Size)
        tmpmsg['硬盘UUID'] = disk.qualifiers['UUID'][1:-1]
        disks.append(tmpmsg)
        diskinfo['硬盘信息'] = diskinfo['硬盘信息']+'硬盘序列号:'+tmpmsg['硬盘序列号']+'\n'
        diskinfo['硬盘信息'] = diskinfo['硬盘信息']+'硬盘设备ID:'+tmpmsg['硬盘设备ID']+'\n'
        diskinfo['硬盘信息'] = diskinfo['硬盘信息']+'硬盘标签:'+tmpmsg['硬盘标签']+'\n'
        diskinfo['硬盘信息'] = diskinfo['硬盘信息']+'硬盘大小:'+tmpmsg['硬盘大小']+'\n'
        diskinfo['硬盘信息'] = diskinfo['硬盘信息']+'硬盘UUID:'+tmpmsg['硬盘UUID']+'\n'
    #for d in disks:
        #print (d)
    return diskinfo

#内存
def getPhysicalMemory(text):
    memorys = []
    memory = {"内存信息":"\n"}
    for mem in c.Win32_PhysicalMemory():
        tmpmsg = {}
        tmpmsg['内存UUID'] = mem.qualifiers['UUID'][1:-1]
        tmpmsg['内存BANK'] = mem.BankLabel
        tmpmsg['内存序列号'] = mem.SerialNumber.strip()
        tmpmsg['内存工作频率'] = str(mem.ConfiguredClockSpeed)
        tmpmsg['内存大小'] = str(mem.Capacity)
        tmpmsg['内存配置电压'] = str(mem.ConfiguredVoltage)
        memorys.append(tmpmsg)
        memory['内存信息'] = memory['内存信息']+'内存UUID:'+tmpmsg['内存UUID']+'\n'
        memory['内存信息'] = memory['内存信息']+'内存BANK:'+tmpmsg['内存BANK']+'\n'
        memory['内存信息'] = memory['内存信息']+'内存序列号:'+tmpmsg['内存序列号']+'\n'
        memory['内存信息'] = memory['内存信息']+'内存工作频率:'+tmpmsg['内存工作频率']+'\n'
        memory['内存信息'] = memory['内存信息']+'内存大小:'+tmpmsg['内存大小']+'\n'
        memory['内存信息'] = memory['内存信息']+'内存配置电压:'+tmpmsg['内存配置电压']+'\n'
    #for m in memorys:
       # print (m)
    return memory

#电池信息，只有笔记本才会有电池选项
def getBattery(text):
    isBatterys = False
    for b in c.Win32_Battery():
        isBatterys = True
    return isBatterys

#网卡mac地址：
def getMacAddress(text):
    macs = []
    mac = {"网卡信息":"\n"}
    for n in  c.Win32_NetworkAdapter():
        mactmp = n.MACAddress
        if mactmp and len(mactmp.strip()) > 5:
            tmpmsg = {}
            tmpmsg['MAC地址'] = n.MACAddress
            tmpmsg['网卡名称'] = n.Name
            tmpmsg['网卡设备ID'] = str(n.DeviceID)
            tmpmsg['网卡适配器类型'] = str(n.AdapterType)
            tmpmsg['网卡速度'] = str(n.Speed)
            macs.append(tmpmsg)
            mac["网卡信息"]=mac["网卡信息"]+"MAC地址:"+tmpmsg['MAC地址']+'\n'
            mac["网卡信息"]=mac["网卡信息"]+"网卡名称:"+tmpmsg['网卡名称']+'\n'
            mac["网卡信息"]=mac["网卡信息"]+"网卡设备ID:"+tmpmsg['网卡设备ID']+'\n'
            mac["网卡信息"]=mac["网卡信息"]+"网卡适配器类型:"+tmpmsg['网卡适配器类型']+'\n'
            mac["网卡信息"]=mac["网卡信息"]+"网卡速度:"+tmpmsg['网卡速度']+'\n'
    #print (macs)
    return mac

def main():

    print(getCPU(''))


if __name__ == '__main__':
    main()
